<?php
	error_reporting(E_ALL^E_NOTICE);
	require_once ('./config/config.php'); 
	require_once ('./class/email.class.php'); 
	require_once ('./class/tools.class.php');
	date_default_timezone_set("PRC");
	session_start();
	if(!empty($_SESSION['user'])){
		echo "<script>location='./index.php';</script>";
		exit();
	}else{
		if($_POST){
			$user=$_POST['user'];
			$pwd=sha1($_POST['pwd']);
			$repwd=sha1($_POST['repwd']);
			$phone=$_POST['phone'];
			$email=$_POST['email'];
			$name=$_POST['name'];
			$time=time();
			if(empty($user) or empty($pwd) or empty($repwd) or empty($email) or empty($name) or empty($phone)){
				echo "<script>alert('请输入完整信息！');location='./reg.php';</script>";
				exit();
			}else{
				if($pwd==$repwd){
					$userRs=mysqli_fetch_array(mysqli_query($con,"select * from user where user='".$user."' or email='".$email."'"));
					if($userRs){
						echo "<script>alert('该账号或邮箱已被注册，请检查后重试！');location='./reg.php';</script>";
						exit();
					}else{
						mysqli_query($con,"INSERT INTO `user` (`uid`, `user`, `password`, `phone`, `name`, `email`,`money`, `state` , `time`) VALUES (NULL, '".$user."', '".$pwd."', '".$phone."', '".$name."', '".$email."','0', '0','".$time."')");
						$smtpserver = "";//SMTP服务器
						$smtpserverport ="25";//SMTP服务器端口
						$smtpusermail = "";//SMTP服务器的用户邮箱
						$smtpemailto = $email;//发送给谁
						$smtpuser = "";//SMTP服务器的用户帐号
						$smtppass = "";//SMTP服务器的用户密码
						$mailsubject = "【某高校图书共享网站】-账号激活";//邮件主题
						$mail = new StdClass;
						$mail->FromName = "【某高校图书共享网站】";
						$mailbody = "您正在进行某高校图书共享网站的注册，请点击链接激活该账号！激活链接：<a href='http://".$_SERVER['SERVER_NAME']."/BookSharing/check.php?user=".$user."&key=".sha1($time)."'>http://".$_SERVER['SERVER_NAME']."/BookSharing/check.php?user=".$user."&key=".sha1($time)."</a>";//邮件内容
						$mailtype = "HTML";//邮件格式（HTML/TXT）,TXT为文本邮件
						$smtp = new smtp($smtpserver,$smtpserverport,true,$smtpuser,$smtppass);//这里面的一个true是表示使用身份验证,否则不使用身份验证.
						$smtp->debug = false;//是否显示发送的调试信息
						$av=$smtp->sendmail($smtpemailto,$smtpusermail, $mailsubject,$mailbody,$mailtype);
						echo "<script>alert('注册成功，请前往邮箱点击链接激活该账号！');location='./login.php';</script>";
						exit();
					}
				}else{
					echo "<script>alert('两次密码输入不一致');location='./reg.php';</script>";
					exit();
				}
			}
		}
	}
?>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>某高校图书共享网站 - 用户注册</title>
		<link rel="stylesheet" href="./auth-assets/css/reset.css" />
		<link rel="stylesheet" href="./auth-assets/css/common.css" />
	</head>
	<body>
		<div class="wrap login_wrap">
			<div class="content">
				
				<div class="logo"></div>
				
				<div class="login_box">	
					
					<div class="login_form">
						<div class="login_title">
							注册
						</div>
						<form action="" method="post">
							
							<div class="form_text_ipt">
								<input name="user" type="text" placeholder="请输入帐号">
							</div>
							<div class="ececk_warning"><span>数据不能为空</span></div>
							<div class="form_text_ipt">
								<input name="pwd" type="password" placeholder="请输入密码">
							</div>
							<div class="ececk_warning"><span>数据不能为空</span></div>
							<div class="form_text_ipt">
								<input name="repwd" type="password" placeholder="请再次输入密码">
							</div>
							<div class="ececk_warning"><span>数据不能为空</span></div>
							<div class="form_text_ipt">
								<input name="phone" type="text" placeholder="请输入手机号">
							</div>
							<div class="ececk_warning"><span>数据不能为空</span></div>
							<div class="form_text_ipt">
								<input name="email" type="email" placeholder="请输入邮箱">
							</div>
							<div class="ececk_warning"><span>数据不能为空</span></div>
							<div class="form_text_ipt">
								<input name="name" type="text" placeholder="请输入姓名">
							</div>
							<div class="ececk_warning"><span>数据不能为空</span></div>
							<div class="form_btn">
								<button type="submit">注册</button>
							</div>
							<div class="form_reg_btn">
								<span>已有帐号？</span><a href="./login.php">马上登录</a>
							</div>
						</form>
						<div class="other_login">
							<div class="left other_left">
								<span>其它登录方式</span>
							</div>
							<div class="right other_right">
								<a href="">华宇通行证</a>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
		<script type="text/javascript" src="./auth-assets/js/jquery.min.js" ></script>
		<script type="text/javascript" src="./auth-assets/js/common.js" ></script>
	</body>
</html>